/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package System.model;

import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 *
 * @author GuloTosh
 */
public class Service {
    int id;
    String nome;
    ServiceValue default_value;
    ServiceValue current_value;
    ArrayList values = new ArrayList<ServiceValue>();

    public Service(int id, String nome) {
        this.id = id;
        this.nome = nome;
        //this.value = value;
    }

    public Service(int id, String nome, ServiceValue ValCurrent,  ServiceValue  Valdefault) {
        this.id = id;
        this.nome = nome;
        this.current_value = ValCurrent;
        this.default_value = Valdefault;

        //this.value = value;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

  

    public ArrayList getValues() {
        return values;
    }

    public void addValues(ServiceValue values) {
        this.values.add(values);
    }

 public JSONObject toJson() throws JSONException{

        JSONObject json = new JSONObject();
        json.put("id", this.getId());
        json.put("name", this.getNome());
        json.put("current", this.current_value.toJson());
        json.put("default", this.default_value.toJson());
        JSONArray jOptions = new JSONArray();

        for (int i = 0; i < values.size(); i++) {
                jOptions.put(((ServiceValue) values.get(i)).toJson());         
        }
        json.put("options", jOptions);

        return json;

   }


    

}
